﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using EnvDTE;
using Microsoft.VisualStudio.SharePoint;
using SP2010DevExtensions.Helper;

namespace SP2010DevExtensions.ItemExtensions
{
    [Export(typeof(ISharePointProjectItemTypeExtension))]
    [SharePointProjectItemType("*")]
    public class MenuItemExtension:ISharePointProjectItemTypeExtension
    {
        public void Initialize(ISharePointProjectItemType projectItemType)
        {
            projectItemType.ProjectItemMenuItemsRequested += ProjectItemTypeProjectItemMenuItemsRequested;
        }

        static void ProjectItemTypeProjectItemMenuItemsRequested(object sender, SharePointProjectItemMenuItemsRequestedEventArgs e)
        {
            var menuItem = e.ViewMenuItems.Add("Copy to 14 Hive");
            menuItem.Click += MenuItemClick;
            menuItem.Text = "Copy to 14 Hive";
        }

        static void MenuItemClick(object sender, MenuItemEventArgs e)
        {
            var projectItem = (ISharePointProjectItem)e.Owner;
            if (projectItem is IMappedFolder)
            {
                var mappedFolder = projectItem as IMappedFolder;
                MenuCommands.CopyTo(mappedFolder);
            }
        }
        //private void test()
        //{
        //    var dteType = (DTE)Package.GetGlobalService(typeof(DTE));

        //    var globalOleServiceProvider = (IOleServiceProvider)dteType;
        //    var globalServiceProvider = new ServiceProvider(globalOleServiceProvider);
        //    var shareProjectService = (ISharePointProjectService)globalServiceProvider.GetService(typeof(ISharePointProjectService));
        //    return shareProjectService.Convert<ISharePointProjectItem, ProjectItem>(mappedFolder);
        //}
    }
}
